infile = open('stud.txt', 'r')
outfile = open('average.txt', 'w')
all_marks = [[], [], []]

while True:
    line = infile.readline()
    if len(line) == 0:
        break
    marks = line.split(';')
    m1, m2, m3 = float(marks[1]), float(marks[2]), float(marks[3])
    all_marks[0].append(m1)
    all_marks[1].append(m2)
    all_marks[2].append(m3)
    student_avg_mark = (m1 + m2 + m3)/3

    outfile.write(str(student_avg_mark) + '\n')

for subject in all_marks:
    subject_avg_mark = 0
    for mark in subject:
        subject_avg_mark += mark/len(subject)
    outfile.write(str(subject_avg_mark))
    if subject != all_marks[-1]:
        outfile.write(' ')

infile.close()
outfile.close()


'''count = 0
for i in total_avg:
    count += i
final_count = count/len(total_avg)
outfile.write(str(final_count))'''


